__author__ = 'pcJxy'

import base64


def int_2_n_bytes(i: int, n: int):
    return i.to_bytes(n, "big")


def bytes_2_int(s: bytes):
    return sum((item * 256 ** idx for idx, item in enumerate(reversed(s))))


def int_2_bytes(i: int):
    return i.to_bytes((i.bit_length() + 7) // 8, "big")


def int_2_b64str(i: int):
    s = int_2_bytes(i)
    return base64.b64encode(s).decode('utf-8')


def b64str_2_int(b64_str: str):
    s = base64.b64decode(b64_str.encode("utf-8"))
    return bytes_2_int(s)
